
<form id="form1" name="form1" method="post" action="">
  <p>
    <label for="textfield">输入要删除的用户名或UID,并选择对应的类型： </label>
    <input type="text" name="word" id="word" />
    <input type="hidden" name="username" id="username" />
    <input type="hidden" name="uid" id="uid" />
    <label>
      <input name="type" type="radio" id="type_0" value="username" />
      用户名</label>
    <label>
      <input name="type" type="radio" id="type_1" value="uid" checked="checked" />
      UID</label>
  </p>
  <p>
    <input type="submit" name="button" id="button" value="提交" />
  </p>
</form>
<?php
if (empty($_POST['word']) || empty($_POST['type'])) {
	echo '请选择正确的用户名或UID,并选择对应的类型!';
	exit;
}
if ($_POST['type'] == 'username') {
	$sql = "select uid from user where username='{$_POST['word']}'";
	$uid = $DB->getValue($sql);
	if (!$uid) {
		echo '不存在该用户!';
		exit;
	}
} else {
	$uid = (int)$_POST['word'];
	$sql = 'select uid from user where uid='.$uid;
	$ret = $DB->getValue($sql);
	if (!$ret) {
		echo '不存在该用户!';
		exit;
	}
}
echo '<pre>';
$tableList = $DB->showTables();
foreach ($tableList as $table) {
	if (substr($table, -7) == '_delete') {
//		$sql = 'drop table '.$table;
//		$DB->exeSql($sql);
		continue;
	}
//	continue;
	$fieldList = $DB->desc($table);
	$hasUid = false;
	foreach ($fieldList as $item) {
		if ($item['field'] == 'uid') {
			$hasUid = true;
		}
	}
	if (!$hasUid) {
		echo $table, "\n";
		continue;
	}
	$tableDel = $table.'_delete';
	$sql = '';
//	$sql = 'create table if not EXISTS '.$tableDel.' like '.$table.';';
//	$sql .= 'insert into '.$tableDel.' (select * from '.$table.' where uid='.$uid.');';
	$sql .= 'delete from '.$table.' where uid='.$uid;
	$ret = $DB->exeSql($sql);
	if (false === $ret) {
		echo $table, ' 表数据删除失败!';
		exit;
	}
	echo $table, '表数据删除完成...', "\n";
}

echo '全部数据处理完成!';
